<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head th:replace="/sys/base :: headFragment(~{::title},~{::link},~{::style})"></head>

<body>
<!--<div class="layui-form base-dialog">-->
<!--    <form class="layui-form layui-form-pane">-->
<!--        <div class="layui-form-item">-->
<!--            <label class="layui-form-label">账号</label>-->
<!--            <div class="layui-input-block">-->
<!--                <input type="text" class="layui-input" id="account" name="account" lay-verify="required|account"-->
<!--                       autocomplete="off">-->
<!--            </div>-->
<!--        </div>-->
<!--        <div class="layui-form-item">-->
<!--            <label class="layui-form-label">密码</label>-->
<!--            <div class="layui-input-block">-->
<!--                <input type="password" class="layui-input" name="pass" lay-verify="required|pass" autocomplete="off">-->
<!--            </div>-->
<!--        </div>-->
<!--        <div class="layui-form-item">-->
<!--            <label class="layui-form-label">重复密码</label>-->
<!--            <div class="layui-input-block">-->
<!--                <input type="password" class="layui-input" name="rePass" lay-verify="required|rePass"-->
<!--                       autocomplete="off">-->
<!--            </div>-->
<!--        </div>-->
<!--        <div class="layui-form-item">-->
<!--            <div class="layui-inline">-->
<!--                <label class="layui-form-label">验证码</label>-->
<!--                <div class="layui-input-block">-->
<!--                    <input type="text" class="layui-input" name="verifyCode" lay-verify="required|verifyCode"-->
<!--                           autocomplete="off">-->
<!--                </div>-->
<!--            </div>-->
<!--            <div class="layui-inline">-->
<!--                <button type="button" class="layui-btn layui-btn-primary" id="verifyCode"-->
<!--                        onclick="$(this).counterLi({waitingTime: 10})">获取验证码-->
<!--                </button>-->
<!--            </div>-->
<!--        </div>-->

<!--        <div class="layui-form-item">-->
<!--            <div class="layui-input-block">-->
<!--                <button class="layui-btn" lay-submit lay-filter="modifyPass">保存</button>-->
<!--                <button type="reset" class="layui-btn layui-btn-primary">取消</button>-->
<!--            </div>-->
<!--        </div>-->
<!--    </form>-->
<!--</div>-->
<div class="layui-form base-dialog">
    <form>
        <div class="layui-form-item">
            <label class="layui-form-label">账号</label>
            <div class="layui-input-inline">
                <input class="layui-input" type="text" id="account" name="account" lay-verify="required|account" autocomplete="off" placeholder="请输入账号">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">新密码</label>
            <div class="layui-input-inline">
                <input class="layui-input" type="password" name="pass" lay-verify="required|pass" autocomplete="off" placeholder="请输入新密码">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">确认密码</label>
            <div class="layui-input-inline">
                <input class="layui-input" type="password" name="rePass" lay-verify="required|rePass" placeholder="再次输入密码">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">验证码</label>
                <div class="layui-input-inline">
                    <input type="text" class="layui-input" name="verifyCode" lay-verify="required|verifyCode" autocomplete="off" placeholder="请输入邮箱验证码">
                </div>
            </div>
            <div class="layui-inline">
                <button type="button" class="layui-btn layui-btn-primary" id="verifyCode" onclick="$(this).counterVerifyCodeLi()">获取验证码</button>
            </div>
        </div>
        <div class="layui-form-item base-finally">
            <button class="layui-btn" lay-submit lay-filter="modifyPass"><i class="fa fa-check-circle"></i> 保存</button>
            <button class="layui-btn btn-secondary base-close-dialog"><i class="fa fa-times-circle"></i> 取消</button>
        </div>
    </form>
</div>

<script th:replace="/sys/base :: scriptFragment"></script>
<!-- TODO RSA非对称加密 -->
<script th:src="@{/static/js/encrypt/jsencrypt.min.js}" charset="utf-8"></script>
<script type="text/javascript" th:inline="javascript">
    layui.use(['form'], function () {
        // 表单对象
        var form = layui.form;
        // 自定义表单密码校验规则:
        // 密码(以字母开头，长度在6~18之间，只能包含字母、数字和下划线)：^[a-zA-Z]\w{5,17}$
        // 强密码(必须包含大小写字母和数字的组合，不能使用特殊字符，长度在 8-10 之间)：^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])[a-zA-Z0-9]{8,10}$
        // 强密码(必须包含大小写字母和数字的组合，可以使用特殊字符，长度在8-10之间)：^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,10}$
        form.verify({
            account: function(value,item) {
                if (!/^[a-zA-Z][a-zA-Z0-9]{4,9}$/.test(value)) {
                    return "以字母开头的5-10位字母或数字组成"
                }
            },
            pass: function(value, item) {
                if (!/^[a-zA-Z]\w{5,9}$/.test(value)) {
                    return "以字母开头，长度在6~10之间，只能包含字母、数字和下划线";
                }
            },
            rePass: function (value, item) {
                var pass = $("input[name='pass']").val();
                if (value !== pass) {
                    return "两次密码输入不一致"
                }
            },
            verifyCode: function(value,item) {
                if (!/^[A-Za-z0-9]{4}$/.test(value)) {
                    return "'由字母、数字组成的4位有效字符串'"
                }
            }
        });
        form.on('submit(modifyPass)', function (data) { //TODO 提交表单
            // 表单字段
            var account = data.field.account;
            var pass = $.encryptRasLI(data.field.pass); // 按照公钥加密
            var verifyCode = data.field.verifyCode;
            $.ajax({
                url: $.getProjectNameLI() + "/sys/admin/modifyPass",
                async: false,
                type: 'post',
                dataType: "json",
                data: {
                    account: account
                    ,pass: pass
                    ,baseVerifyCodeMail: verifyCode
                }
                ,success: function (res) {
                    if (res.code === 0) {
                        layer.msg('更新成功！',{time:3000}, function () {
                            window.top.location.href = $.getProjectNameLI() + "/sys/admin/toLogin"; // 跳转到登陆页面
                        });
                    } else {
                        layer.msg(res.message,{time:3000});
                    }
                }
                ,complete: function (xhr) {
                    $.ajaxCompleteLI(xhr);
                }
            });
            return false; // 阻止表单提交
        });
    });
</script>

</body>
</html>